package top.go2do.auth.business.user.module;

import jakarta.persistence.*;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @Description
 * @Author xingyj
 * @CreateTime 2025/5/15 16:26
 */
@Entity
@Table(name = "user_role")
@IdClass(UserRoleId.class)
@Data
public class UserRolePO {
    @Id
    @Column(name = "user_id", columnDefinition = "BIGINT UNSIGNED COMMENT '用户ID(雪花算法分布式ID)'")
    private Long userId;

    @Id
    @Column(name = "role_id", columnDefinition = "BIGINT UNSIGNED COMMENT '角色ID(雪花算法分布式ID)'")
    private Long roleId;

    @Id
    @Column(name = "app_id", nullable = false, columnDefinition = "VARCHAR(32) COMMENT '所属应用ID'")
    private String appId;

    @Column(name = "created_at", nullable = false, insertable = false, updatable = false,
            columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间'")
    private LocalDateTime createdAt;

}

class UserRoleId implements Serializable {
    private Long userId;
    private Long roleId;
    private String appId;
}
